<template>
  <div class="mechanism">
    <el-container>
      <el-header>
        <div :class="pathMiddle">
          <div class="logo fl">
            <img :src="baseUrl + '/storage/upload/' + agencyLogo" alt="" />
          </div>
          <div class="fullName fl">
            <span>{{ agencyName }}</span>
          </div>

          <el-popover
            placement="bottom"
            width="144"
            popper-class="option-menu"
            :visible-arrow="false"
            trigger="hover"
          >
            <div :class="userGradPre" @click="option" slot="reference"></div>
            <ul>
              <!-- <li>
                <router-link to='/mechanism/home/recommend'>我的推荐</router-link>
              </li> -->

              <li>
                <router-link to="/mechanism/home/editInformation">个人资料</router-link>
                <div class="arrow"></div>
              </li>
              <!-- <li>
                <router-link to='/mechanism/home/editPassword'>修改密码</router-link>
              </li> -->
              <li>
                <router-link to="/mechanism/home/opinion">投诉建议</router-link>
              </li>
              <li>
                <!-- <router-link to='' ></router-link> -->
                <span @click="quit">退出</span>
              </li>
            </ul>
          </el-popover>
          <span v-if="$route.path != '/mechanism/home/menu'" class="weCome fr mr20">
            欢迎您，{{ userInfo.name }}</span
          >
        </div>
      </el-header>
      <el-main class="">
        <nuxt-child />
      </el-main>
      <el-footer>
        <p class="record tc" v-html="record"></p>
        <div class="company tc">
          <span class="company_text" style="margin-right: 15px">技术支持</span>
          <a href="" class="company_logo"></a>
          <span class="company_text">武汉溟宇科惠知识产权服务有限公司</span>
        </div>
      </el-footer>
    </el-container>
  </div>
</template>

<script>
import { RECORD } from "../util/config";
export default {
  data() {
    return {
      agentLogo: "",
      record: RECORD,
      baseUrl: global.baseurl,
    };
  },
  mounted() {
    //在页面加载时读取sessionStorage里的状态信息
    if (sessionStorage.getItem("store")) {
      this.$store.replaceState(
        Object.assign({}, this.$store.state, JSON.parse(sessionStorage.getItem("store")))
      );
    }

    //在页面刷新时将vuex里的信息保存到sessionStorage里
    window.addEventListener("beforeunload", () => {
      sessionStorage.setItem("store", JSON.stringify(this.$store.state));
    });
  },
  computed: {
    userGradPre() {
      if (this.$store.state.user.vip) {
        return "option-vip fr";
      } else {
        return "option fr";
      }
    },
    pathMiddle() {
      let path = this.$route.path;
      if (
        path.indexOf("/mechanism/news") != "-1" ||
        path.indexOf("/mechanism/settlement/purse") != "-1" ||
        path.indexOf("/mechanism/settlement/earnings") != "-1" ||
        path.indexOf("/mechanism/order/waitingAccepting") != "-1" ||
        path.indexOf("/mechanism/order/myOrder") != "-1" ||
        path.indexOf("/mechanism/order/afterKnowledge") != "-1"
      ) {
        return "newsMiddle clearfloat head";
      } else if (path.indexOf("/mechanism/rank") != "-1") {
        return "rankMiddle clearfloat head";
      } else if (path.indexOf("/mechanism/achievement") != "-1") {
        return "achiMiddle clearfloat head";
      }
      return "middle clearfloat head";
    },
    userInfo() {
      return { ...this.$store.state.user };
    },
    agencyLogo() {
      if (this.$store.state.user.agency) {
        return this.$store.state.user.agency.logo;
      } else {
        return "";
      }
    },
    agencyName() {
      if (this.$store.state.user.agency) {
        return this.$store.state.user.agency.agency_name;
      } else {
        return "";
      }
    },
  },
  created() {},
  methods: {
    option() {},
    quit() {
      this.$confirm("是否退出登录?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        center: true,
        type: "warning",
      })
        .then(() => {
          let url = "/login?type=1";
          this.$store.commit("delToken");
          this.$cookies.remove("token");
          this.$store.commit("delUser");
          this.$cookies.remove("user");
          if (process.client) {
            sessionStorage.removeItem("store");
            window.localStorage.setItem("autoLogin", JSON.stringify(false));
          }
          this.$router.replace({
            path: url,
          });
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="less">
//   .el-main {
//   overflow: unset;
// }
.mechanism {
  width: 100%;
  height: 100%;
  .middle {
    width: 980px;
    margin: 0 auto;
  }
  .newsMiddle {
    width: 90%;
    margin: 0 auto;
  }
  .rankMiddle {
    width: 853px;
    margin: 0 auto;
  }
  .achiMiddle {
    width: 1200px;
    margin: 0 auto;
  }
  .el-container {
    width: 100%;
    height: 100%;
    background: rgba(244, 247, 255, 1);
    .el-header {
      padding: 0;
      width: 100%;
      height: 90px !important;
      background: rgba(255, 255, 255, 1);
      .logo {
        height: 50px;
        width: 50px;
        margin-top: 20px;
        margin-right: 10px;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .fullName {
        font-size: 24px;
        color: rgba(27, 27, 27, 1);
        line-height: 90px;
      }
      .option {
        width: 27px;
        height: 27px;
        margin-top: 30px;
        background: url("../assets/img/图标.png") no-repeat;
        background-position: -173px -109px;
        cursor: pointer;
      }
      .option-vip {
        width: 27px;
        height: 27px;
        margin-top: 30px;
        background: url("../assets/img/图标.png") no-repeat;
        background-position: -216px -109px;
        cursor: pointer;
      }
      .weCome {
        font-size: 20px;
        line-height: 90px;
      }
      .weComeVip {
        font-size: 25px;
        color: #ffc125;
        font-weight: 600;
        font-style: italic;
      }
    }
    .el-main {
      padding: 20px 0 0 0;
      height: 100%;
    }
    .el-footer {
      height: 114px !important;
      padding-top: 20px;
      font-size: 15px;
      color: rgba(51, 51, 51, 1);
      background: #ffffff;
      // background: white;
      // .record {

      // }
      .company {
        margin-top: 20px;
        .company_logo {
          display: inline-block;
          width: 48px;
          height: 22px;
          background: url("../assets/img/图标.png") no-repeat;
          background-position: -282px -393px;
        }
        .company_text {
          margin-left: 19px;
          display: inline-block;
          vertical-align: top;
        }
      }
    }
  }
}
@media screen {
  @media (max-width: 1400px) {
    .mechanism {
      .el-container {
        .el-header {
          height: 60px !important;
          .head {
            .logo {
              height: 40px;
              width: 40px;
              margin-top: 10px;
              margin-right: 10px;
            }
            .fullName {
              font-size: 20px;
              color: #1b1b1b;
              line-height: 60px;
            }
            .weCome {
              line-height: 60px;
              font-size: 18px;
            }
            .option-vip {
              margin-top: 15px;
            }
            .option {
              margin-top: 15px;
            }
          }
        }
        .el-footer {
          height: 80px !important;
          padding-top: 10px;
          font-size: 15px;
          color: #333333;

          .company {
            margin-top: 10px;
          }
        }
      }
    }
  }
}
</style>
